*** 1C: Merge Botox and Carrier Data 
********************************************************
*** Append botox to controls, prep as time series

cd /disk/agedisk3/medicare.work/poterba-DUA52260/jetson-dua52260/botox/synth/100pct/raw/

use carrier/carrier_botox_panel.dta, clear
append using carrier/carrier_hcpcs_panel.dta


gen carrier = 1 
append using op/op_botox_panel.dta
append using op/op_hcpcs_panel.dta
replace carrier = 0 if mi(carrier)

** Drop if missing month variable
drop if mi(dt)

*** Rename payment to something familiar 
* We have rprvdpmt from op
* and we have lprvpmt from carrier, which is 20%; so multiply by 5 for estimate of spend
rename rprvdpmt pmt_amt 
replace pmt_amt = 5*lprvpmt if mi(pmt_amt)
drop lprvpmt


*** Remove botox untreated units
*** They are not a control unit nor treated
drop if hcpcs_cd == "botox_untreated"

* Re-panelize to merge op and carrier 
collapse (sum) pmt_amt, by(hcpcs_cd dt)
drop if mi(hcpcs_cd)

*** Encode hcpcs_code to temp group 
encode hcpcs_cd, gen(g)
**** Tag botox 
count if g == 99999
replace g = 99999 if hcpcs_cd == "botox_treated"

*** Full time panel
tsset g dt
tsfill, full
replace pmt_amt = 0 if mi(pmt_amt)

*** Filter to start/end of data 
	*Start of data
drop if dt <  mofd(mdy(1,1,2002))
	* Switch to ICD10 marks end of data
drop if dt >= 669


cd /disk/agedisk3/medicare.work/poterba-DUA52260/jetson-dua52260/botox/synth/100pct/
save op_carrier_100pct_clean_botox.dta, replace 